﻿<cfscript>
/** 
* ORM BookStock
* 
* @hint "Hibernate persistenter t_book_stock. 教材出入库变化情况" 
* 
*/ 

component 
	displayname="public.service.orm.senate.BookStock" 
	output=false 
	persistent=true 
	selectBeforeUpdate=true dynamicInsert=true dynamicUpdate=true 
	cacheuse="Transactional" 
	entityname="BookStock" 
	table="t_book_stock"
	{

	property type="string" name="StockTicket" column="tikect" fieldtype="id" generator="assigned" hint="教材出入库单号";

	property type="numeric" name="FixedPrise" column="fixed_price" hint="码洋";
	property type="numeric" name="DiscountedPrice" column="discounted_price" hint="实洋";
	property type="numeric" name="Stock" column="stock_count" hint="出入库数量";

	property type="string" name="TicketCreateTime" column="opertime" hint="出入库时间";

	property name="Book" fieldtype="many-to-one" fkcolumn="bid" cfc="Book"  hint="教材";
	property name="BookBill" fieldtype="many-to-one" fkcolumn="bbid" cfc="BookBill"  hint="教材出入库票据流水号";
	
	/**
	* @hint "自定义主键规则"
	*/
	public string function getNextID() output=false {
		
		/* 
			主键生成规则 CHAR(13)
			BS + 6位日期代码 [YYMMDD] + 5位流水号
		*/
		
		var nextID = "BS" & dateFormat(now(), "YYMMDD") & numberFormat(1, "0____");
		
		var checkArray = ORMExecuteQuery("select StockTicket from BookStock 
											where 
											StockTicket like :condition
											order by StockTicket desc", {
																	condition="BS" & dateFormat(now(), "YYMMDD") & "_____" }, { maxResults=1 });
		
		if (arrayLen(checkArray)) {
			/* 创建一个追加id */
			nextID = "BS" & dateFormat(now(), "YYMMDD") & numberFormat( right(checkArray[1], 5) + 1, "0____");
		}
		
		return nextID;
	}
	
}

</cfscript>